﻿using System;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace PanoramicData.TickTockBlink.Test
{
	[TestClass]
	public class TimeColorHelperTests
	{
		[TestMethod]
		public void TimeColors()
		{
			// Hours
			Assert.AreEqual(Color.MidnightBlue.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 0, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Black.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 1, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Black.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 2, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Black.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 3, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Black.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 4, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Black.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 5, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Black.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 6, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Black.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 7, 0, 0)).ToArgb());
			Assert.AreEqual(Color.DarkRed.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 8, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Red.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 9, 0, 0)).ToArgb());
			Assert.AreEqual(Color.DarkOrange.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 10, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Yellow.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 11, 0, 0)).ToArgb());
			Assert.AreEqual(Color.DarkGreen.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 12, 0, 0)).ToArgb());
			Assert.AreEqual(Color.LightGreen.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 13, 0, 0)).ToArgb());
			Assert.AreEqual(Color.DarkCyan.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 14, 0, 0)).ToArgb());
			Assert.AreEqual(Color.LightCyan.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 15, 0, 0)).ToArgb());
			Assert.AreEqual(Color.DarkBlue.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 16, 0, 0)).ToArgb());
			Assert.AreEqual(Color.LightBlue.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 17, 0, 0)).ToArgb());
			Assert.AreEqual(Color.DarkMagenta.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 18, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Magenta.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 19, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Gray.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 20, 0, 0)).ToArgb());
			Assert.AreEqual(Color.White.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 21, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Black.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 22, 0, 0)).ToArgb());
			Assert.AreEqual(Color.Black.ToArgb(), TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 23, 0, 0)).ToArgb());

			// Half-hours
			var midnightBlue = Color.MidnightBlue;
			var expectedHalfMidnightColor = Color.FromArgb(midnightBlue.R/2, midnightBlue.G/2, midnightBlue.B/2);
			var actualHalfMidnightColor = TimeColorHelper.GetColor(new DateTime(1970, 1, 1, 0, 30, 0));
			// Difference should not vary by more than one in any of R, G or B
			Assert.IsTrue(Math.Abs(expectedHalfMidnightColor.R - actualHalfMidnightColor.R) <= 1);
			Assert.IsTrue(Math.Abs(expectedHalfMidnightColor.G - actualHalfMidnightColor.G) <= 1);
			Assert.IsTrue(Math.Abs(expectedHalfMidnightColor.B - actualHalfMidnightColor.B) <= 1);
		}

		[TestMethod]
		public void FlashTimes()
		{
			Assert.AreEqual(FlashType.None, TimeColorHelper.GetFlashType(new DateTime(1970, 1, 1, 0, 0, 1)));
			Assert.AreEqual(FlashType.Single, TimeColorHelper.GetFlashType(new DateTime(1970, 1, 1, 0, 15, 0)));
			Assert.AreEqual(FlashType.Double, TimeColorHelper.GetFlashType(new DateTime(1970, 1, 1, 0, 0, 0)));
		}
	}
}
